<template>
	<view class="preview-pdf">
		<pdf v-if="pdfUrl" style="width: 100%; height: 100vh;" :src="pdfUrl" @error="onPdfError"></pdf>
	</view>
</template>

<script>
export default {
	data() {
		return {
			pdfUrl: ''
		}
	},
	methods: {
		onPdfError() {
			uni.showToast({
				title: '合同加载失败',
				icon: 'none'
			})
		}
	},
	onLoad() {
		const url = uni.getStorageSync('pdfUrl')
		console.log('url - 111111111111111111111111111111111', url);

		// this.pdfUrl = opt.url
		uni.downloadFile({
			url,
			success: function (res) {
				var filePath = res.tempFilePath;
				uni.openDocument({
					filePath: filePath,
					showMenu: true,
					success: function (res) {
						console.log('打开文档成功', res);

						setTimeout(() => {
							uni.navigateBack()
						}, 1000);
					}
				});
			}
		});


	}
}
</script>

<style lang="scss" scoped>
.preview-pdf {}
</style>